package com.sumainfor.pc.gmio.service.impl;

import com.google.common.collect.Lists;
import com.sumainfor.common.entity.SearchEntity;
import com.sumainfor.common.util.DateUtils;

import com.sumainfor.common.util.JsonResult;
import com.sumainfor.common.utlis.HtmlUtil;
import com.sumainfor.pc.gmio.dao.BillSearchMapper;
import com.sumainfor.pc.gmio.feign.Zfeign.ZpcEpcFeign;
import com.sumainfor.pc.gmio.feign.Zfeign.ZpcMktFeign;
import com.sumainfor.pc.gmio.feign.Zfeign.ZwxTenantFeign;
import com.sumainfor.pc.gmio.feign.Zfeign.ZzuulFeign;
import net.bytebuddy.asm.Advice;
import org.apache.commons.collections.MapUtils;
import org.apache.commons.lang3.StringUtils;
import org.omg.CORBA.OBJ_ADAPTER;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.awt.*;
import java.io.Serializable;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;

/**
 * <p>
 * 运营部各角色搜索
 * <p>
 *
 * @author: zc
 * @create: 2019-09-19 10:35
 **/
@Service
public class SearchService implements Serializable {

    @Autowired
    ZpcMktFeign zpcMktFeign;
    @Autowired
    ZpcEpcFeign zpcEpcFeign;
    @Autowired
    ZwxTenantFeign zwxTenantFeign;
    @Autowired
    BillSearchMapper billSearchMapper;

    @Autowired
    ZzuulFeign zzuulFeign;


    /**
     * 服务管家
     * @author zhoucong
     * @data 2019/9/19
     * @Param
     * @return
     */
    public JsonResult searchForFugj(String search){

        List<SearchEntity> dataList = Lists.newArrayList();
        //搜索字段不为空
        if(!StringUtils.isBlank(search)){
            //根据小区名#楼号室号，房屋编号搜索训房记录
            SearchEntity Search1 = new SearchEntity();
            List<Map<String,Object>> getFugjTrainingList = zpcMktFeign.getFugjTrainingList(search);
            Search1.setName(String.format("训房记录(%d)",getFugjTrainingList.size()));
            Search1.setRouter("/sys-housekeeper/roomrecord");
            Search1.setList(getFugjTrainingList.stream().map(
                    myItem -> {
                        StringBuffer myItemStr = new StringBuffer();
                        DateUtils.formatDateByMap(myItem);
                        myItemStr.append(HtmlUtil.BR)
                                .append("项目名称:").append(MapUtils.getString(myItem,"ComName"))
                                .append(HtmlUtil.BR)
                                .append("房源编号:").append(MapUtils.getString(myItem,"HouId"))
                                .append(HtmlUtil.BR)
                                .append("训房状态:").append(MapUtils.getString(myItem,"PatStatusOne"))
                                .append(HtmlUtil.BR)
                                .append("详细地址:").append(MapUtils.getString(myItem,"District"))
                                .append("-")
                                .append(MapUtils.getString(myItem,"Street"))
                                .append("-")
                                .append(MapUtils.getString(myItem,"Address"));
                  return HtmlUtil.stringToHTML(myItemStr.toString(), MapUtils.getString(myItem, "HouId"), Color.red);
                    }).collect(Collectors.toList()));
            dataList.add(Search1);
            //根据小区名#楼号室号，房屋编号搜索验房详情
            SearchEntity Search2 = new SearchEntity();
            List<Map<String,Object>> getHoDecorateFugjList = zpcEpcFeign.getHoDecorateFugjList(search);
            Search2.setName(String.format("验房详情(%d)",getHoDecorateFugjList.size()));
            Search2.setRouter("/sys-housekeeper/newcollectnew");
            Search2.setList(getHoDecorateFugjList.stream().map(
                    myItem ->{
                        StringBuffer myItemStr = new StringBuffer();
                        DateUtils.formatDateByMap(myItem);
                        myItemStr.append(HtmlUtil.BR)
                                .append("房源编号:").append(MapUtils.getString(myItem,"HouId"))
                                .append(HtmlUtil.BR)
                                .append("验房状态:").append(MapUtils.getString(myItem,"CheckStatusOne"))
                                .append(HtmlUtil.BR)
                                .append("管家验房:").append(MapUtils.getString(myItem,"IfCheckStateOne"))
                                .append(HtmlUtil.BR)
                                .append("通知管家时间:").append(MapUtils.getString(myItem,"CheckNoticeTime"));
                        return HtmlUtil.stringToHTML(myItemStr.toString(), MapUtils.getString(myItem, "HouId"), Color.red);
                    }).collect(Collectors.toList()));
            dataList.add(Search2);
            //根据租客姓名，手机号搜索租客详情
            SearchEntity Search3 = new SearchEntity();
            List<Map<String,Object>> getTenByPhone = zpcMktFeign.getTenByPhone(search);
            Search3.setName(String.format("租客详情(%d)",getTenByPhone.size()));
            Search3.setRouter("/sys-housekeeper/tenant");
            Search3.setList(getTenByPhone.stream().map(
                    myItem ->{
                        StringBuffer myItemStr = new StringBuffer();
                        DateUtils.formatDateByMap(myItem);
                        myItemStr.append(HtmlUtil.BR)
                                .append("租客姓名:").append(MapUtils.getString(myItem,"TenName"))
                                .append(HtmlUtil.BR)
                                .append("租客id:").append(MapUtils.getString(myItem,"TenId"))
                                .append(HtmlUtil.BR)
                                .append("联系方式:").append(MapUtils.getString(myItem,"TenMode"));
                        return HtmlUtil.stringToHTML(myItemStr.toString(), MapUtils.getString(myItem, "TenName"), Color.red);
                    }).collect(Collectors.toList()));
            dataList.add(Search3);
            //根据租客姓名，手机号搜索维修申请
            List<String> TenIdList = new ArrayList<>();
            if (getTenByPhone.size()>0){
                for (Map<String,Object> map:getTenByPhone) {
                    TenIdList.add(MapUtils.getString(map,"TenId"));
                }

            }

            List<Map<String,Object>> getFugjRepairList = new ArrayList<>();
            SearchEntity Search4 = new SearchEntity();
            if (TenIdList.size()>0){
                Map<String,Object> params = new HashMap<>();
               params.put("RepairsIdList",TenIdList);
                getFugjRepairList = zpcEpcFeign.getFugjRepairList(params);

            }

            Search4.setName(String.format("维修申请(%d)",getFugjRepairList.size()));
            Search4.setRouter("/sys-housekeeper/maintenance");
            Search4.setList(getFugjRepairList.stream().map(
                    myItem ->{
                        StringBuffer myItemStr = new StringBuffer();
                        DateUtils.formatDateByMap(myItem);
                        myItemStr.append(HtmlUtil.BR)
                                .append("维修工单编号:").append(MapUtils.getString(myItem,"RepId"))
                                .append(HtmlUtil.BR)
                                .append("租客id:").append(MapUtils.getString(myItem,"RepairsId"))
                                .append(HtmlUtil.BR)
                                .append("故障描述:").append(MapUtils.getString(myItem,"TroRemark"))
                                .append(HtmlUtil.BR)
                                .append("工单状态:").append(MapUtils.getString(myItem,"OrdStateOne"));
                        return HtmlUtil.stringToHTML(myItemStr.toString(), MapUtils.getString(myItem, "RepId"), Color.red);
                    }).collect(Collectors.toList()));
            dataList.add(Search4);
        }
return JsonResult.success(dataList);

    }

    /**
     * 服务秘书
     * @author zhoucong
     * @data 2019/9/19
     * @Param
     * @return
     */
    public JsonResult searchForFums(String search){

        List<SearchEntity> dataList = Lists.newArrayList();
        //搜索字段不为空
        if(!StringUtils.isBlank(search)){
            //根据租客姓名或者手机号查询租客详情
            SearchEntity Search1 = new SearchEntity();
            List<Map<String,Object>> getNameOrPhoneList = zwxTenantFeign.getNameOrPhoneList(search);
            Search1.setName(String.format("租客详情(%d)",getNameOrPhoneList.size()));
            Search1.setRouter("/sys-ServiceManager/tenantmanagement");
            Search1.setList(getNameOrPhoneList.stream().map(
                    myItem -> {
                        StringBuffer myItemStr = new StringBuffer();
                        DateUtils.formatDateByMap(myItem);
                        myItemStr.append(HtmlUtil.BR)
                                .append("租客id:").append(MapUtils.getString(myItem,"TenId"))
                                .append(HtmlUtil.BR)
                                .append("租客姓名:").append(MapUtils.getString(myItem,"Realname"))
                                .append(HtmlUtil.BR)
                                .append("联系方式:").append(MapUtils.getString(myItem,"TenPhone"));
                        return HtmlUtil.stringToHTML(myItemStr.toString(), MapUtils.getString(myItem, "TenId"), Color.red);
                    }).collect(Collectors.toList()));
            dataList.add(Search1);
            //根据租客姓名或者手机号查询未审核的账单
            List<String> TenIdList = new ArrayList<>();
            if (getNameOrPhoneList.size()>0){
                for (Map<String,Object> map:getNameOrPhoneList) {
                    TenIdList.add(MapUtils.getString(map,"TenId"));
                }
            }
            List<Map<String,Object>> getFumsTenIdSearchList = new ArrayList<>();
            SearchEntity Search2 = new SearchEntity();
            if (TenIdList.size()>0){
                Map<String,Object> params = new HashMap<>();
                params.put("TenIdList",TenIdList);
                getFumsTenIdSearchList = billSearchMapper.getFumsTenIdSearchList(params);

            }

            Search2.setName(String.format("未审核账单(%d)",getFumsTenIdSearchList.size()));
            Search2.setRouter("/sys-servicesecretary/check");
            Search2.setList(getFumsTenIdSearchList.stream().map(
                    myItem ->{
                        StringBuffer myItemStr = new StringBuffer();
                        DateUtils.formatDateByMap(myItem);
                        myItemStr.append(HtmlUtil.BR)
                                .append("账单编号:").append(MapUtils.getString(myItem,"BiId"))
                                .append(HtmlUtil.BR)
                                .append("租客id:").append(MapUtils.getString(myItem,"TenId"))
                                .append(HtmlUtil.BR)
                                .append("账单名称:").append(MapUtils.getString(myItem,"BiName"));
                        return HtmlUtil.stringToHTML(myItemStr.toString(), MapUtils.getString(myItem, "BiId"), Color.red);
                    }).collect(Collectors.toList()));
            dataList.add(Search2);
            //根据项目编号楼号室号房屋编号查询账单录入、查看
            SearchEntity Search3 = new SearchEntity();
            List<Map<String,Object>> getFumsHouInfoList = zpcMktFeign.getFumsHouInfoList(search);
            List<String> HouInfoIdList = new ArrayList<>();
            if (getFumsHouInfoList.size()>0){
                for (Map<String,Object> map:getFumsHouInfoList) {
                    HouInfoIdList.add(MapUtils.getString(map,"HouInfoId"));
                }
            }
            List<Map<String,Object>> getHouInfoBillList = new ArrayList<>();
          if (HouInfoIdList.size()>0){
          Map<String,Object> params = new HashMap<>();
          params.put("HouInfoIdList",HouInfoIdList);
              getHouInfoBillList = billSearchMapper.getHouInfoBillList(params);
          }

            Search3.setName(String.format("账单录入/查看(%d)",getHouInfoBillList.size()));
            Search3.setRouter("/sys-director/billaudit");
            Search3.setList(getHouInfoBillList.stream().map(
                    myItem ->{
                        StringBuffer myItemStr = new StringBuffer();
                        DateUtils.formatDateByMap(myItem);
                        myItemStr.append(HtmlUtil.BR)
                                .append("账单编号:").append(MapUtils.getString(myItem,"BiId"))
                                .append(HtmlUtil.BR)
                                .append("房源编号:").append(MapUtils.getString(myItem,"HouInfoId"))
                                .append(HtmlUtil.BR)
                                .append("账单类型:").append(MapUtils.getString(myItem,"BiTypeOne"));
                        return HtmlUtil.stringToHTML(myItemStr.toString(), MapUtils.getString(myItem, "BiId"), Color.red);
                    }).collect(Collectors.toList()));
            dataList.add(Search3);

        }
        return JsonResult.success(dataList);
    }


    /**
     * 租后主管
     * @author zhoucong
     * @data 2019/9/19
     * @Param
     * @return
     */
    public JsonResult searchForZhzg(String search){
        List<SearchEntity> dataList = Lists.newArrayList();
        //搜索字段不为空
        if(!StringUtils.isBlank(search)){
            //根据小区名#楼号室号，房屋编号搜索训房记录
            SearchEntity Search1 = new SearchEntity();
            List<Map<String,Object>> getFugjTrainingList = zpcMktFeign.getFugjTrainingList(search);
            Search1.setName(String.format("巡房记录(%d)",getFugjTrainingList.size()));
            Search1.setRouter("/sys-housekeeper/roomrecord");
            Search1.setList(getFugjTrainingList.stream().map(
                    myItem -> {
                        StringBuffer myItemStr = new StringBuffer();
                        DateUtils.formatDateByMap(myItem);
                        myItemStr.append(HtmlUtil.BR)
                                .append("项目名称:").append(MapUtils.getString(myItem,"ComName"))
                                .append(HtmlUtil.BR)
                                .append("房源编号:").append(MapUtils.getString(myItem,"HouId"))
                                .append(HtmlUtil.BR)
                                .append("巡房状态:").append(MapUtils.getString(myItem,"PatStatusOne"))
                                .append(HtmlUtil.BR)
                                .append("详细地址:").append(MapUtils.getString(myItem,"District"))
                                .append("-")
                                .append(MapUtils.getString(myItem,"Street"))
                                .append("-")
                                .append(MapUtils.getString(myItem,"Address"));
                        return HtmlUtil.stringToHTML(myItemStr.toString(), MapUtils.getString(myItem, "HouId"), Color.red);
                    }).collect(Collectors.toList()));
            dataList.add(Search1);
            //根据小区名#楼号室号，房屋编号搜索验房详情
            SearchEntity Search2 = new SearchEntity();
            List<Map<String,Object>> getHoDecorateFugjList = zpcEpcFeign.getHoDecorateFugjList(search);
            Search2.setName(String.format("验房详情(%d)",getHoDecorateFugjList.size()));
            Search2.setRouter("/sys-housekeeper/newcollectnew");
            Search2.setList(getHoDecorateFugjList.stream().map(
                    myItem ->{
                        StringBuffer myItemStr = new StringBuffer();
                        DateUtils.formatDateByMap(myItem);
                        myItemStr.append(HtmlUtil.BR)
                                .append("房源编号:").append(MapUtils.getString(myItem,"HouId"))
                                .append(HtmlUtil.BR)
                                .append("验房状态:").append(MapUtils.getString(myItem,"CheckStatusOne"))
                                .append(HtmlUtil.BR)
                                .append("管家验房:").append(MapUtils.getString(myItem,"IfCheckStateOne"))
                                .append(HtmlUtil.BR)
                                .append("通知管家时间:").append(MapUtils.getString(myItem,"CheckNoticeTime"));
                        return HtmlUtil.stringToHTML(myItemStr.toString(), MapUtils.getString(myItem, "HouId"), Color.red);
                    }).collect(Collectors.toList()));
            dataList.add(Search2);


            //根据租客姓名或者手机号查询租客详情
            SearchEntity Search3 = new SearchEntity();
            List<Map<String,Object>> getNameOrPhoneList = zwxTenantFeign.getNameOrPhoneList(search);
            Search3.setName(String.format("租客详情(%d)",getNameOrPhoneList.size()));
            Search3.setRouter("/sys-ServiceManager/tenantmanagement");
            Search3.setList(getNameOrPhoneList.stream().map(
                    myItem -> {
                        StringBuffer myItemStr = new StringBuffer();
                        DateUtils.formatDateByMap(myItem);
                        myItemStr.append(HtmlUtil.BR)
                                .append("租客id:").append(MapUtils.getString(myItem,"TenId"))
                                .append(HtmlUtil.BR)
                                .append("租客姓名:").append(MapUtils.getString(myItem,"Realname"))
                                .append(HtmlUtil.BR)
                                .append("联系方式:").append(MapUtils.getString(myItem,"TenPhone"));
                        return HtmlUtil.stringToHTML(myItemStr.toString(), MapUtils.getString(myItem, "TenId"), Color.red);
                    }).collect(Collectors.toList()));
            dataList.add(Search3);

            //根据租客姓名，手机号搜索维修申请
            List<String> TenIdList = new ArrayList<>();
            if (getNameOrPhoneList.size()>0){
                for (Map<String,Object> map:getNameOrPhoneList) {
                    TenIdList.add(MapUtils.getString(map,"TenId"));
                }
            }
            List<Map<String,Object>> getFugjRepairList = new ArrayList<>();
            SearchEntity Search4 = new SearchEntity();
            if (TenIdList.size()>0){
                Map<String,Object> params = new HashMap<>();
                params.put("RepairsIdList",TenIdList);
                getFugjRepairList = zpcEpcFeign.getFugjRepairList(params);
            }
            Search4.setName(String.format("维修申请(%d)",getFugjRepairList.size()));
            Search4.setRouter("/sys-engineeringassistant/repairmanage");
            Search4.setList(getFugjRepairList.stream().map(
                    myItem ->{
                        StringBuffer myItemStr = new StringBuffer();
                        DateUtils.formatDateByMap(myItem);
                        myItemStr.append(HtmlUtil.BR)
                                .append("维修工单编号:").append(MapUtils.getString(myItem,"RepId"))
                                .append(HtmlUtil.BR)
                                .append("租客id:").append(MapUtils.getString(myItem,"RepairsId"))
                                .append(HtmlUtil.BR)
                                .append("故障描述:").append(MapUtils.getString(myItem,"TroRemark"))
                                .append(HtmlUtil.BR)
                                .append("工单状态:").append(MapUtils.getString(myItem,"OrdStateOne"));
                        return HtmlUtil.stringToHTML(myItemStr.toString(), MapUtils.getString(myItem, "RepId"), Color.red);
                    }).collect(Collectors.toList()));
            dataList.add(Search4);


            //根据租客姓名或者手机号查询待审核的账单
            List<Map<String,Object>> getFumsTenIdSearchList = new ArrayList<>();
            SearchEntity Search5 = new SearchEntity();
            if (TenIdList.size()>0){
                Map<String,Object> params = new HashMap<>();
                params.put("TenIdList",TenIdList);
                getFumsTenIdSearchList = billSearchMapper.getFumsTenIdSearchList(params);
            }
            Search5.setName(String.format("未审核账单(%d)",getFumsTenIdSearchList.size()));
            Search5.setRouter("/sys-director/billaudit");
            Search5.setList(getFumsTenIdSearchList.stream().map(
                    myItem ->{
                        StringBuffer myItemStr = new StringBuffer();
                        DateUtils.formatDateByMap(myItem);
                        myItemStr.append(HtmlUtil.BR)
                                .append("账单编号:").append(MapUtils.getString(myItem,"BiId"))
                                .append(HtmlUtil.BR)
                                .append("租客id:").append(MapUtils.getString(myItem,"TenId"))
                                .append(HtmlUtil.BR)
                                .append("账单名称:").append(MapUtils.getString(myItem,"BiName"));
                        return HtmlUtil.stringToHTML(myItemStr.toString(), MapUtils.getString(myItem, "BiId"), Color.red);
                    }).collect(Collectors.toList()));
            dataList.add(Search5);


            //根据员工手机号获取员工详情
            List<Map<String,Object>> getZhzgEmployeesList = zzuulFeign.getZhzgEmployeesList(search);
            SearchEntity Search6 = new SearchEntity();
            Search6.setName(String.format("员工详情(%d)",getZhzgEmployeesList.size()));
            Search6.setRouter("/sys-director/managestaff");
            Search6.setList(getZhzgEmployeesList.stream().map(
                    myItem ->{
                        StringBuffer myItemStr = new StringBuffer();
                        DateUtils.formatDateByMap(myItem);
                        myItemStr.append(HtmlUtil.BR)
                                .append("员工姓名:").append(MapUtils.getString(myItem,"name"))
                                .append(HtmlUtil.BR)
                                .append("员工角色:").append(MapUtils.getString(myItem,"role_name"))
                                .append(HtmlUtil.BR)
                                .append("联系方式:").append(MapUtils.getString(myItem,"mobile"));
                        return HtmlUtil.stringToHTML(myItemStr.toString(), MapUtils.getString(myItem, "name"), Color.red);
                    }).collect(Collectors.toList()));
            dataList.add(Search6);
          //根据项目编号项目名称楼号室号 房屋编号获取房源详情
            List<Map<String,Object>> getZhzgHouIdList = zpcMktFeign.getZhzgHouIdList(search);
            SearchEntity Search7 = new SearchEntity();
            Search7.setName(String.format("房源详情(%d)",getZhzgHouIdList.size()));
            Search7.setRouter("/sys-ServiceManager/rentalsourestateMent");
            Search7.setList(getZhzgHouIdList.stream().map(
                    myItem ->{
                        StringBuffer myItemStr = new StringBuffer();
                        DateUtils.formatDateByMap(myItem);
                        myItemStr.append(HtmlUtil.BR)
                                .append("房源编号:").append(MapUtils.getString(myItem,"HouInfoId"))
                                .append(HtmlUtil.BR)
                                .append("房源状态:").append(MapUtils.getString(myItem,"StateOne"))
                                .append(HtmlUtil.BR)
                                .append("详细地址:").append(MapUtils.getString(myItem,"District"))
                                .append("-")
                                .append(MapUtils.getString(myItem,"Street"))
                                .append("-")
                                .append(MapUtils.getString(myItem,"Address"));
                        return HtmlUtil.stringToHTML(myItemStr.toString(), MapUtils.getString(myItem, "HouInfoId"), Color.red);
                    }).collect(Collectors.toList()));
            dataList.add(Search7);
            //根据租客姓名手机号获取客诉管理
            List<Map<String,Object>> getZhzgComplaintList = new ArrayList<>();
            SearchEntity Search8 = new SearchEntity();
            if (TenIdList.size()>0){
                Map<String,Object> params = new HashMap<>();
                params.put("TenIdList",TenIdList);
                getZhzgComplaintList = billSearchMapper.getZhzgComplaintList(params);
            }
            Search8.setName(String.format("客诉管理(%d)",getZhzgComplaintList.size()));
            Search8.setRouter("/sys-director/complaint");
            Search8.setList(getZhzgComplaintList.stream().map(
                    myItem ->{
                        StringBuffer myItemStr = new StringBuffer();
                        DateUtils.formatDateByMap(myItem);
                        myItemStr.append(HtmlUtil.BR)
                                .append("客户投诉编号:").append(MapUtils.getString(myItem,"CompId"))
                                .append(HtmlUtil.BR)
                                .append("租客编号:").append(MapUtils.getString(myItem,"TenId"))
                                .append(HtmlUtil.BR)
                                .append("投诉内容:").append(MapUtils.getString(myItem,"ContentOne"));
                        return HtmlUtil.stringToHTML(myItemStr.toString(), MapUtils.getString(myItem, "CompId"), Color.red);
                    }).collect(Collectors.toList()));
            dataList.add(Search8);
        }
        return JsonResult.success(dataList);





    }


    /**
     * 运营助理 or 运营经理
     * @author zhoucong
     * @data 2019/9/19
     * @Param
     * @return
     */
    public JsonResult searchForYyzlorYyjl(String search){

        List<SearchEntity> dataList = Lists.newArrayList();
        //搜索字段不为空
        if(!StringUtils.isBlank(search)){
          List<String> TenIdList = new ArrayList<>();
            //根据租客姓名或者手机号查询租客详情
            SearchEntity Search1 = new SearchEntity();
            List<Map<String,Object>> getNameOrPhoneList = zwxTenantFeign.getNameOrPhoneList(search);
            Search1.setName(String.format("租客详情(%d)",getNameOrPhoneList.size()));
            Search1.setRouter("/sys-ServiceManager/tenantmanagement");
            Search1.setList(getNameOrPhoneList.stream().map(
                    myItem -> {
                        StringBuffer myItemStr = new StringBuffer();
                        DateUtils.formatDateByMap(myItem);
                        myItemStr.append(HtmlUtil.BR)
                                .append("租客id:").append(MapUtils.getString(myItem,"TenId"))
                                .append(HtmlUtil.BR)
                                .append("租客姓名:").append(MapUtils.getString(myItem,"Realname"))
                                .append(HtmlUtil.BR)
                                .append("联系方式:").append(MapUtils.getString(myItem,"TenPhone"));
                        return HtmlUtil.stringToHTML(myItemStr.toString(), MapUtils.getString(myItem, "TenId"), Color.red);
                    }).collect(Collectors.toList()));
            dataList.add(Search1);

            //根据租客姓名或者手机号查询待审核的账单
            List<Map<String,Object>> getFumsTenIdSearchList = new ArrayList<>();
            SearchEntity Search2 = new SearchEntity();
            if (TenIdList.size()>0){
                Map<String,Object> params = new HashMap<>();
                params.put("TenIdList",TenIdList);
                getFumsTenIdSearchList = billSearchMapper.getFumsTenIdSearchList(params);
            }
            Search2.setName(String.format("未审核账单(%d)",getFumsTenIdSearchList.size()));
            Search2.setRouter("/sys-director/billaudit");
            Search2.setList(getFumsTenIdSearchList.stream().map(
                    myItem ->{
                        StringBuffer myItemStr = new StringBuffer();
                        DateUtils.formatDateByMap(myItem);
                        myItemStr.append(HtmlUtil.BR)
                                .append("账单编号:").append(MapUtils.getString(myItem,"BiId"))
                                .append(HtmlUtil.BR)
                                .append("租客id:").append(MapUtils.getString(myItem,"TenId"))
                                .append(HtmlUtil.BR)
                                .append("账单名称:").append(MapUtils.getString(myItem,"BiName"));
                        return HtmlUtil.stringToHTML(myItemStr.toString(), MapUtils.getString(myItem, "BiId"), Color.red);
                    }).collect(Collectors.toList()));
            dataList.add(Search2);

            //根据租客姓名，手机号搜索维修申请
            if (getNameOrPhoneList.size()>0){
                for (Map<String,Object> map:getNameOrPhoneList) {
                    TenIdList.add(MapUtils.getString(map,"TenId"));
                }
            }
            List<Map<String,Object>> getFugjRepairList = new ArrayList<>();
            SearchEntity Search3 = new SearchEntity();
            if (TenIdList.size()>0){
                Map<String,Object> params = new HashMap<>();
                params.put("RepairsIdList",TenIdList);
                getFugjRepairList = zpcEpcFeign.getFugjRepairList(params);
            }
            Search3.setName(String.format("维修申请(%d)",getFugjRepairList.size()));
            Search3.setRouter("/sys-engineeringassistant/repairmanage");
            Search3.setList(getFugjRepairList.stream().map(
                    myItem ->{
                        StringBuffer myItemStr = new StringBuffer();
                        DateUtils.formatDateByMap(myItem);
                        myItemStr.append(HtmlUtil.BR)
                                .append("维修工单编号:").append(MapUtils.getString(myItem,"RepId"))
                                .append(HtmlUtil.BR)
                                .append("租客id:").append(MapUtils.getString(myItem,"RepairsId"))
                                .append(HtmlUtil.BR)
                                .append("故障描述:").append(MapUtils.getString(myItem,"TroRemark"))
                                .append(HtmlUtil.BR)
                                .append("工单状态:").append(MapUtils.getString(myItem,"OrdStateOne"));
                        return HtmlUtil.stringToHTML(myItemStr.toString(), MapUtils.getString(myItem, "RepId"), Color.red);
                    }).collect(Collectors.toList()));
            dataList.add(Search3);


            //根据小区名#楼号室号，房屋编号搜索训房记录
            SearchEntity Search4 = new SearchEntity();
            List<Map<String,Object>> getFugjTrainingList = zpcMktFeign.getFugjTrainingList(search);
            Search4.setName(String.format("巡房记录(%d)",getFugjTrainingList.size()));
            Search4.setRouter("/sys-housekeeper/roomrecord");
            Search4.setList(getFugjTrainingList.stream().map(
                    myItem -> {
                        StringBuffer myItemStr = new StringBuffer();
                        DateUtils.formatDateByMap(myItem);
                        myItemStr.append(HtmlUtil.BR)
                                .append("项目名称:").append(MapUtils.getString(myItem,"ComName"))
                                .append(HtmlUtil.BR)
                                .append("房源编号:").append(MapUtils.getString(myItem,"HouId"))
                                .append(HtmlUtil.BR)
                                .append("巡房状态:").append(MapUtils.getString(myItem,"PatStatusOne"))
                                .append(HtmlUtil.BR)
                                .append("详细地址:").append(MapUtils.getString(myItem,"District"))
                                .append("-")
                                .append(MapUtils.getString(myItem,"Street"))
                                .append("-")
                                .append(MapUtils.getString(myItem,"Address"));
                        return HtmlUtil.stringToHTML(myItemStr.toString(), MapUtils.getString(myItem, "HouId"), Color.red);
                    }).collect(Collectors.toList()));
            dataList.add(Search4);
            //根据小区名#楼号室号，房屋编号搜索验房详情
            SearchEntity Search5 = new SearchEntity();
            List<Map<String,Object>> getHoDecorateFugjList = zpcEpcFeign.getHoDecorateFugjList(search);
            Search5.setName(String.format("验房详情(%d)",getHoDecorateFugjList.size()));
            Search5.setRouter("/sys-housekeeper/newcollectnew");
            Search5.setList(getHoDecorateFugjList.stream().map(
                    myItem ->{
                        StringBuffer myItemStr = new StringBuffer();
                        DateUtils.formatDateByMap(myItem);
                        myItemStr.append(HtmlUtil.BR)
                                .append("房源编号:").append(MapUtils.getString(myItem,"HouId"))
                                .append(HtmlUtil.BR)
                                .append("验房状态:").append(MapUtils.getString(myItem,"CheckStatusOne"))
                                .append(HtmlUtil.BR)
                                .append("管家验房:").append(MapUtils.getString(myItem,"IfCheckStateOne"))
                                .append(HtmlUtil.BR)
                                .append("通知管家时间:").append(MapUtils.getString(myItem,"CheckNoticeTime"));
                        return HtmlUtil.stringToHTML(myItemStr.toString(), MapUtils.getString(myItem, "HouId"), Color.red);
                    }).collect(Collectors.toList()));
            dataList.add(Search5);

            //根据项目编号项目名称楼号室号 房屋编号获取房源详情
            List<Map<String,Object>> getZhzgHouIdList = zpcMktFeign.getZhzgHouIdList(search);
            SearchEntity Search6 = new SearchEntity();
            Search6.setName(String.format("房源详情(%d)",getZhzgHouIdList.size()));
            Search6.setRouter("/sys-ServiceManager/rentalsourestateMent");
            Search6.setList(getZhzgHouIdList.stream().map(
                    myItem ->{
                        StringBuffer myItemStr = new StringBuffer();
                        DateUtils.formatDateByMap(myItem);
                        myItemStr.append(HtmlUtil.BR)
                                .append("房源编号:").append(MapUtils.getString(myItem,"HouInfoId"))
                                .append(HtmlUtil.BR)
                                .append("房源状态:").append(MapUtils.getString(myItem,"StateOne"))
                                .append(HtmlUtil.BR)
                                .append("详细地址:").append(MapUtils.getString(myItem,"District"))
                                .append("-")
                                .append(MapUtils.getString(myItem,"Street"))
                                .append("-")
                                .append(MapUtils.getString(myItem,"Address"));
                        return HtmlUtil.stringToHTML(myItemStr.toString(), MapUtils.getString(myItem, "HouInfoId"), Color.red);
                    }).collect(Collectors.toList()));
            dataList.add(Search6);

            //根据员工手机号获取员工详情
            List<Map<String,Object>> getZhzgEmployeesList = zzuulFeign.getZhzgEmployeesList(search);
            SearchEntity Search7 = new SearchEntity();
            Search7.setName(String.format("员工详情(%d)",getZhzgEmployeesList.size()));
            Search7.setRouter("/sys-director/managestaff");
            Search7.setList(getZhzgEmployeesList.stream().map(
                    myItem ->{
                        StringBuffer myItemStr = new StringBuffer();
                        DateUtils.formatDateByMap(myItem);
                        myItemStr.append(HtmlUtil.BR)
                                .append("员工姓名:").append(MapUtils.getString(myItem,"name"))
                                .append(HtmlUtil.BR)
                                .append("员工角色:").append(MapUtils.getString(myItem,"role_name"))
                                .append(HtmlUtil.BR)
                                .append("联系方式:").append(MapUtils.getString(myItem,"mobile"));
                        return HtmlUtil.stringToHTML(myItemStr.toString(), MapUtils.getString(myItem, "name"), Color.red);
                    }).collect(Collectors.toList()));
            dataList.add(Search7);

           //根据业主手机号获取业主变更
            //获取业主信息集合
            List<String> OwIdList = new ArrayList<>();
            //业主信息变更集合
            List<Map<String,Object>> YyzlOwList = new ArrayList<>();
            //业主信息变更去重集合
            List<Map<String,Object>> YyzlOwOneList = new ArrayList<>();
            //业主信息集合
            List<Map<String,Object>> YyzlOwnerList = zpcMktFeign.YyzlOwnerList(search);
            if (YyzlOwnerList.size()>0){
                for (Map<String,Object> map:YyzlOwnerList) {
                    OwIdList.add(MapUtils.getString(map,"OwId"));
                }
            }
            if (OwIdList.size()>0){
                Map<String,Object> params = new HashMap<>();
                params.put("OwIdList",OwIdList);
                //业主提前收房
                List<Map<String,Object>> getYyzlOwadvanceList = billSearchMapper.getYyzlOwadvanceList(params);
                //业主联系人
                List<Map<String,Object>> getYyzlOwcontactList = billSearchMapper.getYyzlOwcontactList(params);
                //业主收款人
                List<Map<String,Object>> getYyzlOwpayeeList = billSearchMapper.getYyzlOwpayeeList(params);
                //业主成员变更
                List<Map<String,Object>> getYyzlOwmemberList = billSearchMapper.getYyzlOwmemberList(params);
                YyzlOwList.addAll(getYyzlOwadvanceList);
                YyzlOwList.addAll(getYyzlOwcontactList);
                YyzlOwList.addAll(getYyzlOwpayeeList);
                YyzlOwList.addAll(getYyzlOwmemberList);
            }

         if (YyzlOwList.size()>0&&YyzlOwnerList.size()>0){
             for (Map<String,Object> map1:YyzlOwList) {
                 for (Map<String,Object> map2:YyzlOwnerList) {
                     if (MapUtils.getString(map1,"OwId")!=null&&MapUtils.getString(map2,"OwId") !=null&&MapUtils.getString(map1,"OwId").equals(MapUtils.getString(map2,"OwId"))){
                         map1.putAll(map2);
                     }
                 }
             }
             //去重
             for (int i=0;i<YyzlOwList.size();i++) {
                 if (!YyzlOwOneList.contains(YyzlOwList.get(i))){
                     YyzlOwOneList.add(YyzlOwList.get(i));
                 }
             }
         }

            SearchEntity Search8 = new SearchEntity();
            Search8.setName(String.format("变更发起(%d)",YyzlOwOneList.size()));
            Search8.setRouter("/sys-QuestionCenter/proprietorCollection");
            Search8.setList(YyzlOwOneList.stream().map(
                    myItem ->{
                        StringBuffer myItemStr = new StringBuffer();
                        DateUtils.formatDateByMap(myItem);
                        myItemStr.append(HtmlUtil.BR)
                                .append("房源编号:").append(MapUtils.getString(myItem,"HouId"))
                                .append(HtmlUtil.BR)
                                .append("业主姓名:").append(MapUtils.getString(myItem,"OwName"))
                                .append(HtmlUtil.BR)
                                .append("联系方式:").append(MapUtils.getString(myItem,"OwPhone"));
                        return HtmlUtil.stringToHTML(myItemStr.toString(), MapUtils.getString(myItem, "OwName"), Color.red);
                    }).collect(Collectors.toList()));
            dataList.add(Search8);

        }
        return JsonResult.success(dataList);

    }




}
